

import java.util.ArrayList;

import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

import com.pizza.hibernate.Pizza;

public class PizzaAdapterList extends JPanel{
	int width , height;
	ArrayList<Pizza> pizzaList=null;
	JScrollPane scrollPane = new JScrollPane();
	ArrayList<PizzaRow> pizzaRows = new ArrayList<PizzaRow>();
	public PizzaAdapterList(int width, int height,ArrayList<Pizza> pizzaList) {
		super();
		scrollPane.setViewportView(this);
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		scrollPane.setHorizontalScrollBarPolicy(
	            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
	    scrollPane.setVerticalScrollBarPolicy(
	            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		setBounds(150, 0, width, height);
		this.setVisible(true);
		this.width = width;
		this.height = height;
		this.pizzaList=pizzaList;
		createRows();
//		showFirstThree();
	}
//	private void showFirstThree() {
//		for (int i = 0; i < 3; i++) {
//			pizzaRows.get(i).setVisible(true);
//		}
//	}
	public void createRows() {
		for (int i = 0; i < pizzaList.size(); i++) {
			pizzaRows.add(new PizzaRow(i*130, width, height/3, pizzaList.get(i)));
		}
		for (PizzaRow pizzaRow : pizzaRows) {
			pizzaRow.setVisible(false);
			this.add(pizzaRow);
		}
	}
	
}
